﻿/*----------------------------------------------------------------
 * 
 * 版权所有：Copyright (C) 2013
 * 
 * 文件名：ArticleUnitTest.txt
 * 文件功能描述：
 * 
 * 
 * 作 者：zhangq
 * 邮 箱：ifunnyface@outlook.com
 * 日 期：2013-01-07 15:35:04
 * 
 * 
 * 修改标识： Author 
 * 修改描述： 相关描述
 * 
 * ---------------------------------------------------------------- */

using Common.Extensions.Where;
using Infrastructure;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data.Entity;
using DomainModel;

namespace ManagerUnitTest
{
    [TestClass]
    public class ArticleUnitTest
    {
        static IManager.IManagerArticle manager;


        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext { get; set; }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {
            Database.SetInitializer<EFDBContext>(null);
            manager = new Manager.ManagerArticle()
           {
               //IDAPartition = new DataAccess.DataAccessArticlePartition()
           };
        }
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        [ClassCleanup()]
        public static void MyClassCleanup()
        {

            manager = null;
        }
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        [TestMethod]
        public void AddTest()
        {

            var partionInfo = new ArticlePartitionInfo()
                {
                    Description = "test001",
                    Enabled = 1,
                    Name = "test003",
                    ParentId = "0",
                    SortNumber = 3
                };
            var m = manager.AddPartition(partionInfo);

            Assert.AreNotEqual(false, m);
        }


        [TestMethod]
        public void UpdateTest()
        {

            var partionInfo = new ArticlePartitionInfo()
            {
                Description = "test001-update",
                Enabled = 1,
                Name = "test002",
                ParentId = "0",
                SortNumber = 4,
                PartitionId = "2"
            };
            var m = manager.UpdatePartition(partionInfo);

            Assert.AreNotEqual(false, m);
        }



        [TestMethod]
        public void GetPartitionTest()
        {
            var list = manager.GetPartitions();
            if (null != list && list.Count > 0)
            {
                var m = manager.GetPartition(list[0].PartitionId);

                Assert.AreNotEqual(null, m);
            }
            Assert.Fail("no data");
        }



        [TestMethod]
        public void GetPartitionsTest()
        {

            var m = manager.GetPartitions();

            Assert.AreNotEqual(null, m);
        }


        [TestMethod]
        public void DeleteTest()
        {
            var list = manager.GetPartitions();
            if (null != list && list.Count > 0)
            {
                var m = manager.DeletePartition(list[0].PartitionId);

                Assert.AreNotEqual(false, m);
            }
            Assert.Fail("no data");
        }


        [TestMethod]
        public void LoadAllPartitionTest()
        {

            var p = PredicateExtension.True<ArticlePartitionInfo>();
            p = p.And(u => u.Name.Contains("001"));

            int count;
            var list = manager.LoadAll(p, 1, 10);

            Assert.AreNotEqual(null, list);

        }


        [TestMethod]
        public void MaxTest()
        {
            var p = manager.Max("XW");

            Assert.AreNotEqual(null, p);

        }

    }
}
